package org.example;
//哈啊哈
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;

public class SnakeGame extends JFrame {

    private CardLayout cardLayout;
    private JPanel cardPanel;
    private MenuPanel menuPanel;
    private PreparePanel preparePanel;
    private GamePanel gamePanel;

    enum Direction {
        UP, DOWN, LEFT, RIGHT
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            SnakeGame game = new SnakeGame();
            game.setVisible(true);
        });
    }

    public SnakeGame() {
        setTitle("贪吃蛇游戏");
       setSize(800, 800);
        //setBounds(1200,1500,800,800);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
       // setResizable(false);

        cardLayout = new CardLayout();
        cardPanel = new JPanel(cardLayout);

        menuPanel = new MenuPanel(this);
        preparePanel = new PreparePanel(this);
        gamePanel = new GamePanel(this);

        cardPanel.add(menuPanel, "Menu");
        cardPanel.add(preparePanel, "Prepare");
        cardPanel.add(gamePanel, "Game");

        add(cardPanel);
        pack();
    }

    public void showMenu() {
        cardLayout.show(cardPanel, "Menu");
    }

    public void showPrepare() {
        cardLayout.show(cardPanel, "Prepare");
    }

    public void showGame(String mapType, String p1skillType, String p2skillType, String modeType, String playerMode,String timeMode,String skinType1,String skinType2) {
        int i = skinType1.charAt(0) - '1'; // 字符 '1' 转换为整数 1
        int j = skinType2.charAt(0) - '1';
        gamePanel.startNewGame(mapType, p1skillType, p2skillType, modeType, playerMode, timeMode, i, j);
        cardLayout.show(cardPanel, "Game");
    }
}